package logic

import (
	"ViewSrv/global/model"
	"context"

	"ViewSrv/internal/svc"
	"ViewSrv/view"

	"github.com/zeromicro/go-zero/core/logx"
)

type MyLikesLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMyLikesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MyLikesLogic {
	return &MyLikesLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *MyLikesLogic) MyLikes(in *view.MyLikesRequest) (*view.MyLikesResponse, error) {
	// todo: add your logic here and delete this line
	var classes []model.Classes
	var videos []model.Video
	model.DB.Model(&model.ClassesLike{}).Joins("join classes on classes.id = classes_likes.classes_id").Select("classes.*").Find(&classes)
	model.DB.Model(&model.VideoLike{}).Joins("join videos on videos.id = video_likes.video_id").Select("videos.*").Find(&videos)
	var Data []*view.LikeData
	for _, class := range classes {
		var data = &view.LikeData{
			Type: "剧集",
			Name: class.Name,
			Id:   int64(class.ID),
		}
		Data = append(Data, data)
	}
	for _, video := range videos {
		var data = &view.LikeData{
			Type: "视频",
			Name: video.Title,
			Id:   int64(video.ID),
		}
		Data = append(Data, data)
	}
	return &view.MyLikesResponse{
		Likes: Data,
	}, nil
}
